﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Windvoice.Blog;

namespace Windvoice.Areas.Manage.Controllers
{
    public class CommentController : ManagerControllerBase
    {
        //
        // GET: /Manage/Comment/
        public ActionResult Index(int? page)
        {
            int PageIndex = page==null?1:page.Value;
            int PageSize = 16;
            int RecordCount = 0;
            ViewBag.Comments = Comment.GetList(PageIndex, PageSize, 0, String.Empty, out RecordCount);
            ViewBag.PageSize = 16;
            ViewBag.RecordCount = RecordCount;
            return View();
        }


        public ActionResult Reply(int id)
        {
            return View(Comment.Find(id));
        }

        [HttpPost]
        public ActionResult Reply(FormCollection formValues)
        {
            var comment = Comment.Find(Convert.ToInt32(formValues["id"]));

            comment.Reply = formValues["reply"];
            comment.ReplyTime = DateTime.Now;

            comment.Update();
            return RedirectToAction("index");
        }

        [HttpPost]
        public ActionResult Delete(int id)
        {
            if (id > 0)
            {
                Comment.Find(id).Delete();
                return AjaxResult();
            }
            return AjaxResult(result: false, message: "参数错误！");
        }
    }
}
